package handler

import (
	"encoding/json"
	"go-test/src/com/miao/common/logger"
	"go-test/src/com/miao/server"
	"go-test/src/com/miao/server/context"
)

type ServerPacket struct {
	Body []byte
	BType byte
}

type LoginBody struct {
	Uid,Username,Avatar string
}

type LoginRespBody struct {
	Token,Msg string
}

type HeartBeatBody struct {

}

type BaseHandler interface {
	handler(packet ServerPacket,channelContext *context.ChannelContext)
}


func (loginBody LoginBody) handler(packet ServerPacket,ctx *context.ChannelContext)  {
	bytes, _ := json.Marshal(loginBody)
	logger.Infof("收到登录请求:%s",string(bytes))
	//log.Println("登陆请求",loginBody)
	server.BindUser("wang",ctx)
	loginRespBody:=LoginRespBody{Token:"ddddd",Msg:"登录响应成功"}
	bodyBytes, err := json.Marshal(loginRespBody)
	if err!=nil {
		logger.Errorf("json解析失败，错误原因:%s",err.Error())
		return
	}
	pack:=ServerPacket{BType:2,Body:bodyBytes}
	server.SendToUser(pack,ctx.GroupContext,"wang")
}

func (heartBeatBody HeartBeatBody) handler(packet ServerPacket,ctx *context.ChannelContext){

}


